package td;

import java.util.Random;

import ui.OneTowerView;

public class OneTower extends Tower {
	/*Constructor for the OneTower*/
	public OneTower(){
		super();
		this.range = 2;
		this.bullet = new SingleBullet(3, StatusEffects.None);
		this.speed = 1;
		this.cost = 30;
		this.viewable = new OneTowerView(this);
	}
	
	public OneTower(Field position) {
		super(position);
		this.range = 2;
		this.bullet = new SingleBullet(3, StatusEffects.None);
		this.speed = 1;
		this.cost = 30;
		this.viewable = new OneTowerView(this);
	}

	/* A method for shooting a bullet. */
	public void shoot(Enemy target) {
		Random rand = new Random();
		int cut = rand.nextInt();
		/*10% chance of shooting a CutterBullet*/
		if (cut % (50/this.sliceChance) == 1) {
			CutterBullet cutbullet = new CutterBullet(3, StatusEffects.None);
			target.getHurt(cutbullet);
		} else {
			/* Applying bullet damage. */
			target.getHurt(this.bullet);
		}
	}

	/*Applying stone effects*/
	public void upgrade(MagicStones stone, int stoneplace) {
		/*If the slot already contains a stone remove its effect because it will be replaced*/
		if (this.stones[stoneplace] != null) {
			degrade(stoneplace);
		} 
			switch (stone) {
			/*Applying Blue stone effect (+1 range)*/
			case Blue:
				this.stones[stoneplace]=stone;
				this.range += 1;
				/*Recalculating inrange Fields*/
				this.inrange.clear();
				this.inRange(this.position, 1);
				break;
			/*Applying Red stone effect (+1 damage)*/
			case Red:
				this.stones[stoneplace]=stone;
				this.bullet.damage += 1;
				break;
			/*Applying Yellow stone effect (-0.25 speed)*/
			case Yellow:
				this.stones[stoneplace]=stone;
				this.speed -= 0.25;
				break;
			/*Applying Rainbow stone effect (DoT effect)*/
			case Rainbow:
				this.stones[stoneplace]=stone;
				this.bullet.status = StatusEffects.Slow;
				break;
			}
		
	}

	/*Removing stone effects*/
	public void degrade(int stoneplace) {
		switch (this.stones[stoneplace]) {
		case Blue:
			this.range -= 1;
			this.inrange.clear();
			this.inRange(this.position, 1);
			break;
		case Red:
			this.bullet.damage -= 1;
			break;
		case Yellow:
			this.speed += 0.25;
			break;
		case Rainbow:
			this.bullet.status = StatusEffects.None;
			break;
		}

	}
	
	/*Applying fog effect (-1 range)*/
	public void applyFog() {
		this.range -= 1;
		this.fogged = true;
		this.viewable.update();
	}

	/*Removing fog effect*/
	public void removeFog() {
		this.range += 1;
		this.fogged = false;
		this.viewable.update();
	}

}
